<div class="breadcrumbs" id="breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            <a href="#">财务管理</a>
        </li>

        <li>
            <a href="#">平台账户明细</a>
        </li>
    </ul>
    <div>
        <input type="hidden" id="cupage" value="1"/>
        <input type="hidden" id="total" value="1"/>
        <input type="hidden" id="formurl" value="/manager/money/getSystemMoneyPage"/>
        <input type="hidden" id="startTime" name="startTime" value=""/>
        <input type="hidden" id="endTime" name="endTime" value=""/>
    </div>
</div>

<div class="page-content">
    <div class="row">
        <div class="col-xs-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        <i class="icon-reorder"></i>
                        筛选条件
                    </h3>
                </div>
                <div class="panel-body">
                    <form class="form-horizontal">
                        <label for="date1" class="col-sm-1 control-label">日期:</label>
                        <div class="col-md-2">
                            <input type="text" name="regular" class="form-control datepicker" id="date1" onBlur="onb()">
                        </div>
                        <label for="search_type" class="col-sm-1 control-label">流水类型:</label>
                        <div class="col-md-1">
                            <select class="form-control dictSelect" id="search_type">
                                <option value="">请选择</option>
                                <option value="1">出账</option>
                                <option value="2">入账</option>
                            </select>
                        </div>
                        <label for="search_order_type" class="col-sm-1 control-label">订单类型:</label>
                    <div class="col-md-1">
                            <select class="form-control dictSelect" id="search_order_type">
                                <option value="">请选择</option>
                                <option value="1">平台费用</option>
                                <option value="2">佣金收入</option>
                                <option value="3">佣金支出</option>
                                <option value="4">提现打款</option>
                                <option value="5">推荐奖励</option>
                            </select>
                        </div>
                        <div class="col-md-1">
                            <input type="button" id="btn-load" class="btn btn-primary btn-pikaqiu"
                                   data-loading-text="加载中..." value="查 询"/>
                        </div>
                    </form>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        <i class="icon-reorder"></i>
                        平台账户明细列表
                        <span style="padding-left: 5%;">累计入账:</span>
                        <span id="inMoney">0</span>元&nbsp;&nbsp;&nbsp;
                        <span style="padding-left: 8%;">累计出账:</span>
                        <span id="outMoney">0</span>元&nbsp;&nbsp;&nbsp;
                        <span style="padding-left: 8%;">提现中:</span>
                        <span id="txMoney">0</span>元&nbsp;&nbsp;&nbsp;
                        <span style="padding-left: 8%;">用户余额:</span>
                        <span id="userMoney">0</span>元&nbsp;&nbsp;&nbsp;
                        <span style="padding-left: 8%;">净收入:</span>
                        <span id="sumMoney">0</span>元&nbsp;&nbsp;&nbsp;
                    </h3>
                    <div class="btn-add-pikaqiu">
                        <button class="btn btn-xs" data-toggle="modal" data-target="#addSystemMoneyModal"><i class="icon-plus"></i> 添 加</button>
                    </div>
                </div>
                <div class="panel-body">
                    <div class="table-responsive">
                        <table id="sample-table-2" class="table table-striped table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>交易类型</th>
                                <th>订单类型</th>
                                <th>交易金额</th>
                                <th>交易时间</th>
                                <th>创建人</th>
                                <th>数据来源</th>
                                <th>备注</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="loadData">

                            </tbody>
                        </table>
                        <!--#include file="/admin/include/page.html"-->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="addSystemMoneyModal" tabindex="-1" role="dialog" aria-labelledby="addSystemMoneyModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">新增账户流水</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form" id="addSystemMoneyForm">
                    <input type="hidden" id="id">
                    <div class="form-group">
                        <label for="money" class="col-sm-2 control-label">交易金额</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="money" placeholder="100">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="remark" class="col-sm-2 control-label">备注</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="remark" placeholder="2018-11-05购买产品">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="type" class="col-sm-2 control-label">交易类型</label>
                        <div class="col-sm-10" id="type">
                            <input name="type" class="ace" value="1" type="radio" checked="checked">
                            <span class="lbl"> 出账 </span>
                            <input name="type" class="ace" value="2" type="radio">
                            <span class="lbl"> 入账 </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="order_type" class="col-sm-2 control-label">订单类型</label>
                        <div class="col-sm-10" id="order_type">
                            <input name="order_type" class="ace" value="1" type="radio" checked="checked">
                            <span class="lbl"> 平台费用 </span>
                            <input name="order_type" class="ace" value="2" type="radio">
                            <span class="lbl"> 佣金收入 </span>
                            <input name="order_type" class="ace" value="3" type="radio">
                            <span class="lbl"> 佣金支出 </span>
                            <input name="order_type" class="ace" value="4" type="radio">
                            <span class="lbl"> 提现打款 </span>
                            <input name="order_type" class="ace" value="5" type="radio">
                            <span class="lbl"> 推荐奖励 </span>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="addConfirm()">确认</button>
            </div>
        </div>
    </div>
</div>

<script>
    $("#btn-load").on("click", function () {
        var a = $(this);
        a.button("loading");
        $("#cupage").val("1");
        loadData();

    });
    initDate();
    function loadData() {
        var para = {
            curPage: $("#cupage").val(),
            type: $("#search_type").val(),
            order_type: $("#search_order_type").val(),
            startTime: $("#startTime").val(),
            endTime: $("#endTime").val()
        };
        loadGetServer($("#formurl").val(), para, function (data) {
            var $loadData = $("#loadData");
            $loadData.html("");
            var list = data.page.list;
            var html_ = "";
            for (var i = 0; i < list.length; i++) {
                html_ += "<tr>";
                var type = list[i].type;
                var order_type = list[i].order_type;
                if(type === 1){
                    html_ += "<td> 出账 </td>"
                } else if(type === 2) {
                    html_ += "<td> 入账 </td>"
                } else {
                    html_ += "<td></td>"
                }
                if(order_type === 1){
                    html_ += "<td> 平台费用 </td>"
                } else if(order_type === 2){
                    html_ += "<td> 佣金收入 </td>"
                } else if(order_type === 3){
                    html_ += "<td> 佣金支出 </td>"
                } else if(order_type === 4){
                    html_ += "<td> 提现打款 </td>"
                } else if(order_type === 5){
                    html_ += "<td> 推荐奖励 </td>"
                } else {
                    html_ += "<td></td>"
                }
                html_ += "<td>" + list[i].money + "</td><td>" + list[i].create_date + "</td><td>" + list[i].realname + "</td>";
                var source_type = list[i].source_type;
                if(source_type === 0){
                    html_ += "<td> 系统添加 </td>"
                } else {
                    html_ += "<td> 人工添加</td>"
                }
                html_ += "<td>" + list[i].remark + "</td>";
                html_ += "<td><div class='hidden-sm hidden-xs btn-group'>";
                if(source_type === 0){
                    html_ += "<button class='btn btn-xs btn-default' title='删除记录'><i class='icon-remove bigger-120'></i>删除记录</button>";
                } else {
                    html_ += "<button class='btn btn-xs btn-info' title='删除记录' onclick='deleteMoneyConfirm(" + list[i].id + ")'><i class='icon-remove bigger-120'></i>删除记录</button>";
                }
                html_ += "</td></tr>";
            }
            $loadData.html(html_);
            pageValue(data);
            pageData();
            $('#inMoney').text(data.inMoney);
            $('#outMoney').text(data.outMoney);
            $('#sumMoney').text(data.sumMoney);
            $('#userMoney').text(data.userMoney);
            $('#txMoney').text(data.txMoney);
            $("#btn-load").button("reset");
        });
    }

    loadData();

    function deleteMoneyConfirm(id) {
        var r = confirm("是否确定删除该记录？");
        if (r == true) {
            deleteMoney(id);
        }
    }

    function deleteMoney(id) {
        var para = {
            id: id
        };
        loadGetServer('/manager/money/deleteSystemMoney', para, function (data) {
            if (data.code != 0) {
                alert(data.msg);
            } else {
                alert('操作成功')
                $('#txModal').modal('hide');
            }
            loadData();
        });
    }

    function addConfirm(){
        var para = {
            type : $("#type input:radio[name='type']:checked").val(),
            order_type : $("#order_type input:radio[name='order_type']:checked").val(),
            money: $("#money").val(),
            remark: $("#remark").val()
        };
        loadGetServer('/manager/money/addSystemMoney', para, function (data) {
            if(data.code != 0){
                alert(data.msg);
            }else{
                alert('操作成功')
                $('#addSystemMoneyModal').modal('hide');
            }
            loadData();
        });
    }

    $('#addSystemMoneyModal').on('show.bs.modal', function () {
        $("#addSystemMoneyForm")[0].reset();
    })
</script>